package com.ztjy.dao;

import com.ztjy.common.Constant;
import org.apache.spark.sql.SparkSession;

/**
 * <p>Description: sparksession单例对象</p>
 *
 * <p>Copyright: © 2018-2018 北京掌通未来科技有限公司.All rights reserved.</p>
 *
 * @author zhangjiaxing
 *
 * @date 2018-05-18 18:16:22
 **/
public class MySparkSession {

    private static SparkSession sparkSession = null;

    public static SparkSession init(String appName) {
        if (null == sparkSession) {
            sparkSession = SparkSession
                    .builder()
                    .appName(appName)
                    .config("spark.sql.warehouse.dir", Constant.WAREHOUSE_LOCATION)
                    .enableHiveSupport()
                    .getOrCreate();
        }

        return sparkSession;
    }

    public static SparkSession getSparkSession() {
        return sparkSession;
    }
}
